/// @tags: DP Meet in Middle
#include <cstdio>
#include <iostream>

using std::cin;
using std::cout;

namespace BlueQuantum {

typedef unsigned long long ULL;

constexpr int MAXN = 53, BIT = 25;

int n;
int rel1[MAXN], rel2[MAXN], rel12[MAXN];
int g[1 << BIT];
bool f[1 << BIT];

inline int main() {
  cin >> n;
  int fmid = n / 2, cmid = (n + 1) / 2;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      char c;
      cin >> c;
      c -= '0';
      if (i < fmid && j < fmid) rel1[i] |= c << j;
      if (i < fmid && j >= fmid) rel12[i] |= c << (j - fmid);
      if (i >= fmid && j >= fmid) rel2[i] |= c << (j - fmid);
    }
  }
  f[0] = true;
  for (int i = 1, ilim = (1 << fmid); i < ilim; ++i) {
    /// @note 第一个一的位置可以预处理
    for (int j = 0; j < fmid; ++j) {
      if ((i >> j) & 1) {
        int tmp = 1 << j;
        if ((f[i ^ tmp]) && (((rel1[j] | tmp) & i) == i)) f[i] = true;
        break;
      }
    }
  }
  g[0] = 1;
  for (int i = 1, ilim = 1 << cmid; i < ilim; ++i) {
    for (int j = fmid; j < n; ++j) {
      if ((i >> (j - fmid)) & 1) {
        g[i] = g[i ^ (1 << (j - fmid))];
        g[i] += g[i & rel2[j]];
        break;
      }
    }
  }
  ULL ans = 0;
  for (int i = 0, ilim = 1 << fmid; i < ilim; ++i) {
    if (f[i]) {
      int x = (1 << cmid) - 1;
      for (int j = 0; j < fmid; ++j)
        if ((i >> j) & 1) x &= rel12[j];
      ans += g[x];
    }
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("cows.in", "r", stdin);
  freopen("cows.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
